<?php

/**new
 * @file classes/journal/DMDVCSDAO.inc.php
 * Copyright (c) 2003-2012 John Willinsky
 * Edit by: Ngoc Diệp
 *for retrieving and modifying DMTK objects.
 */


define('DM_FIELD_MA', 'ma_dvcs');
define('DM_FIELD_TEN', 'ten_dvcs');
define('DM_FIELD_NONE', null);



import ('classes.acct.DMDVCS');

class DMDVCSDAO extends DAO {

function &getDMDVCSSearch($searchType = null, $search = null, $searchMatch = null) {

		$paramArray = array();
		$searchSql = '';

		$searchTypeMap = array(
			DM_FIELD_MA => 'dm_dvcs.ma_dvcs',
			DM_FIELD_TEN => 'dm_dvcs.ten_dvcs'
		);

		if (!empty($search) && isset($searchTypeMap[$searchType])) {
			$fieldName = $searchTypeMap[$searchType];
			switch ($searchMatch) {
				case 'is':
					$searchSql = "AND LOWER($fieldName) = LOWER(?)";
					$paramArray[] = $search;
					break;
				case 'contains':
					$searchSql = "AND LOWER($fieldName) LIKE LOWER(?)";
					$paramArray[] = '%' . $search . '%';
					break;
				case 'startsWith':
					$searchSql = "AND LOWER($fieldName) LIKE LOWER(?)";
					$paramArray[] = $search . '%';
					break;
			}
		}
		$result =& $this->retrieve(
				"SELECT * FROM DM_DVCS WHERE ma_dvcs !='' ". $searchSql. " ORDER BY ma_dvcs",
			$paramArray
		);

		$returner = new DAOResultFactory($result, $this, '_returnDMDVCSFromRow');
		return $returner;
	}




function &_returnDMDVCSFromRow(&$row) {
		$DMDVCS = new DMDVCS($row['ma_dvcs'], $row['ten_dvcs']);
		return $DMDVCS;
	}
}

?>
